import {reqBannerList, reqCategroyList, reqFloorList} from '@/api'
const state = {
    categoryList:[],
    bannerList:[],
    floorList:[]
}
const mutations = {
    RECEIVE_CATEGROYLIST(state,categoryList){
        state.categoryList = categoryList
    },
    RECEIVE_BANNERLIST(state,bannerlist){
        state.bannerList = bannerlist
    },
    RECEIVE_FLOORLIST(state,floorList){
        state.floorList = floorList
    }
}
const actions = {
    // 异步请求获取数据,提交给commit,修改state的对应数据
    // getCategoryList({commit}){
    //     reqCategroyList().then((response)=>{
    //         commit(RECEIVE_CATEGROYLIST,response.data)
    //     })
    // }
    // async 和 await 使用同步代码达到解决异步效果
    async getCategoryList({commit}){
        const result = await reqCategroyList()
        if(result.code === 200){
            commit('RECEIVE_CATEGROYLIST',result.data)
        }
    },
    async getBannerList({commit}){
        const result = await reqBannerList()
        if(result.code === 200){
            commit('RECEIVE_BANNERLIST',result.data)
        }
    },
    async getFloorList({commit}){
        const result = await reqFloorList()
        if(result.code === 200){
            commit('RECEIVE_FLOORLIST',result.data)
        }
    }
}


const getters = {}

export default {
    state,
    mutations,
    actions,
    getters
}